/*************************************************************************
    > File Name: 5.show_two.c
    > Author: Ykk
    > Mail: 3393579535@qq.com 
    > Created Time: 2023年05月15日 星期一 20时54分41秒
 ************************************************************************/

#include <stdio.h>
#include <arpa/inet.h>

int main() {
    unsigned int arr[4] = {0x12345678, 0x87654321, 0xdeadbeef, 0xbaadf00d};
    unsigned char *c = (unsigned char*) &arr[0];

    printf("Array in memory:\n");
    for (int i = 0; i < sizeof(arr); i++)
	{
        printf("%p: %02x\n", (void*) &c[i], c[i]);
    }

    // 判断系统的字节序 
    if (*c == 0x78)
	{
        printf("\nLittle endian\n");
    } else {
        printf("\nBig endian\n");
    }

	for (int i = 0; i < 4; i++)
	{
	    arr[i] = ntohl(arr[i]);
    }
    for (int i = 0; i < sizeof(arr); i++) {
        printf("%p: %02x\n", (void*) &c[i], c[i]);
    }

    return 0;
}
